package com.ruoyi.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.provider.domain.AhctCaseCode;
import com.ruoyi.provider.domain.AhctDefineDamage;
import com.ruoyi.provider.domain.AhctDefineDamageCode;
import com.ruoyi.provider.mapper.AhctDefineDamageMapper;
import com.ruoyi.provider.mapper.AhctDefineDamageProjectMapper;
import com.ruoyi.provider.mapper.AhctImageMapper;
import com.ruoyi.provider.service.AhctDefineDamageService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
* @author Wang RuLong
* @description 针对表【ahct_define_damage(定损报批信息)】的数据库操作Service实现
* @createDate 2024-05-17 10:58:33
*/
@Service
public class AhctDefineDamageServiceImpl extends ServiceImpl<AhctDefineDamageMapper, AhctDefineDamage>
    implements AhctDefineDamageService{

    @Resource
    private AhctDefineDamageMapper ahctDefineDamageMapper;

    @Resource
    private AhctImageMapper ahctImageMapper;

    @Resource
    private AhctDefineDamageProjectMapper ahctDefineDamageProjectMapper;



    //查勘审核通过后新增到定损列表
    @Override
    public void insertCaseExamine(Integer id) {
        ahctDefineDamageMapper.insertCaseExamine(id);
    }


    //新增定损项目
    @Override
    public void insertDamage(AhctDefineDamageCode ahctDefineDamageCode) {

        List<String> list = ahctDefineDamageCode.getAddress_code();
        String addResCode = String.join(",",list);
        AhctDefineDamage ahctDefineDamage = new AhctDefineDamage();
        ahctDefineDamage.setAddress_code(addResCode);
        ahctDefineDamage.setCase_number(ahctDefineDamageCode.getCase_number());
        ahctDefineDamage.setTotal_amount(ahctDefineDamageCode.getTotal_amount());
        ahctDefineDamage.setAccident_address(ahctDefineDamageCode.getAccident_address());
        ahctDefineDamage.setDamage_type(ahctDefineDamageCode.getDamage_type());
        ahctDefineDamage.setRemarks(ahctDefineDamageCode.getRemarks());
        ahctDefineDamage.setOpening_bank(ahctDefineDamageCode.getOpening_bank());
        ahctDefineDamage.setBank_account_number(ahctDefineDamageCode.getBank_account_number());
        ahctDefineDamage.setTax_rate(ahctDefineDamageCode.getTax_rate());
        ahctDefineDamage.setInsurer(ahctDefineDamageCode.getInsurer());
        ahctDefineDamage.setCar_number(ahctDefineDamageCode.getCar_number());
        ahctDefineDamage.setSurveyer(ahctDefineDamageCode.getSurveyer());

        ahctDefineDamageMapper.insertDamage(ahctDefineDamage);
    }


    //获取定损列表
    @Override
    public PageInfo<AhctDefineDamage> getDamage(AhctDefineDamage ahctDefineDamage, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        List<AhctDefineDamage> damageList = ahctDefineDamageMapper.getDamage(ahctDefineDamage);

        PageInfo<AhctDefineDamage> pageInfo;

        pageInfo = new PageInfo<>(damageList);

        return pageInfo;
    }


    //定损信息修改
    @Override
    public void updateDamage(AhctDefineDamageCode ahctDefineDamageCode) {

        List<String>  list  = ahctDefineDamageCode.getAddress_code();
        String addResCode = String.join(",",list);
        AhctDefineDamage ahctDefineDamage = new AhctDefineDamage();
        ahctDefineDamage.setAddress_code(addResCode);
        ahctDefineDamage.setId(ahctDefineDamageCode.getId());
        ahctDefineDamage.setCase_number(ahctDefineDamageCode.getCase_number());
        ahctDefineDamage.setDamage_type(ahctDefineDamageCode.getDamage_type());
        ahctDefineDamage.setAccident_address(ahctDefineDamageCode.getAccident_address());
        ahctDefineDamage.setTotal_amount(ahctDefineDamageCode.getTotal_amount());
        ahctDefineDamage.setRemarks(ahctDefineDamageCode.getRemarks());
        ahctDefineDamage.setOpening_bank(ahctDefineDamageCode.getOpening_bank());
        ahctDefineDamage.setTax_rate(ahctDefineDamageCode.getTax_rate());
        ahctDefineDamage.setBank_account_number(ahctDefineDamageCode.getBank_account_number());
        ahctDefineDamage.setInsurer(ahctDefineDamageCode.getInsurer());
        ahctDefineDamage.setCar_number(ahctDefineDamageCode.getCar_number());
        ahctDefineDamage.setSurveyer(ahctDefineDamageCode.getSurveyer());

        ahctDefineDamageMapper.updateDamage(ahctDefineDamage);
    }


    //定损信息删除
    @Transactional
    @Override
    public void deleteDamage(Integer id ,String case_number) {
        //删除定损项目时,需同时删除照片还有定损项目列表
        ahctDefineDamageMapper.deleteDamage(id);//删除定损项目

        ahctImageMapper.deleteImg(case_number);//删除照片

        ahctDefineDamageProjectMapper.deleteProject(id);//删除定损项目列表

    }



    //定损审核
    @Override
    public void updateStatus(String status, String case_number) {

        ahctDefineDamageMapper.updateStatus(status,case_number);
    }

    @Override
    public void insertMeanwhile(AhctCaseCode ahctCaseCode) {

        List<String> list = ahctCaseCode.getAddress_code();
        String addResCode = String.join(",",list);
        AhctDefineDamage ahctDefineDamage = new AhctDefineDamage();
        ahctDefineDamage.setCase_number(ahctCaseCode.getCase_number());
        ahctDefineDamage.setInsurer(ahctCaseCode.getCompany_name());
        ahctDefineDamage.setCar_number(ahctCaseCode.getCar_number());
        ahctDefineDamage.setSurveyer(ahctCaseCode.getSurveyer());
        ahctDefineDamage.setProvince(ahctCaseCode.getProvince());
        ahctDefineDamage.setCity(ahctCaseCode.getCity());
        ahctDefineDamage.setArea(ahctCaseCode.getArea());
        ahctDefineDamage.setAccident_address(ahctCaseCode.getAccident_address());
        ahctDefineDamage.setAddress_code(addResCode);
        ahctDefineDamage.setDamage_type(ahctCaseCode.getCase_type());

        ahctDefineDamageMapper.insertLoss(ahctDefineDamage);
    }


}




